package com.dykj.fireFighting.server.base.maintenancePerson.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.maintenancePerson.dto.MaintenancePersonDto;
import com.dykj.fireFighting.api.base.maintenancePerson.entity.MaintenancePerson;
import com.dykj.fireFighting.api.base.maintenancePerson.service.IMaintenancePersonService;

import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.maintenancePerson.mapper.MaintenancePersonMapper;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 维保单位人员信息
 *
 * @Author JacksonTu
 * @Date  2021-11-03 09:08:51
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class MaintenancePersonServiceImpl extends BaseServiceImpl<MaintenancePersonMapper, MaintenancePerson> implements IMaintenancePersonService {


    @Override
    public PageVo<MaintenancePerson> queryList(MaintenancePersonDto maintenancePersonDto) {

        HashMap<String, Object> params = new HashMap<>(16);
        if(null !=maintenancePersonDto.getName() && StringUtils.isNotBlank(maintenancePersonDto.getName())){
            params.put("name",maintenancePersonDto.getName());
        }
        if(null !=maintenancePersonDto.getPhone() && StringUtils.isNotBlank(maintenancePersonDto.getPhone())){
            params.put("phone",maintenancePersonDto.getPhone());
        }
        if(null !=maintenancePersonDto.getPostDuty() && StringUtils.isNotBlank(maintenancePersonDto.getPostDuty())){
            params.put("postDuty",maintenancePersonDto.getPostDuty());
        }
        if(null !=maintenancePersonDto.getDuty() && StringUtils.isNotBlank(maintenancePersonDto.getDuty())){
            params.put("duty",maintenancePersonDto.getDuty());
        }
        params.put("unitId",maintenancePersonDto.getUnitId());
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(maintenancePersonDto.getPage());
        // 设置页大小
        page.setSize(maintenancePersonDto.getLimit());
        IPage<MaintenancePerson> iPage = this.baseMapper.queryList(page,params );
        return new PageVo(iPage);
    }

    @Override
    public PageVo<MaintenancePerson> getUserBySocialUnit(MaintenancePersonDto maintenancePersonDto) {
        HashMap<String, Object> params = new HashMap<>(16);
        if(null !=maintenancePersonDto.getName() && StringUtils.isNotBlank(maintenancePersonDto.getName())){
            params.put("name",maintenancePersonDto.getName());
        }
        if(null !=maintenancePersonDto.getPhone() && StringUtils.isNotBlank(maintenancePersonDto.getPhone())){
            params.put("phone",maintenancePersonDto.getPhone());
        }
        if(null !=maintenancePersonDto.getPostDuty() && StringUtils.isNotBlank(maintenancePersonDto.getPostDuty())){
            params.put("postDuty",maintenancePersonDto.getPostDuty());
        }
        if(null !=maintenancePersonDto.getDuty() && StringUtils.isNotBlank(maintenancePersonDto.getDuty())){
            params.put("duty",maintenancePersonDto.getDuty());
        }
        params.put("socialUnitId",maintenancePersonDto.getUnitId());
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(maintenancePersonDto.getPage());
        // 设置页大小
        page.setSize(maintenancePersonDto.getLimit());
        return new PageVo<MaintenancePerson>(this.baseMapper.getUserBySocialUnit(page,params));
    }

    @Override
    public MaintenancePerson getInfoById(String id) {
        return this.baseMapper.getInfoById(id);
    }
}
